from typing import TypedDict
from ..baseapp import db


class HostMachineInfo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)
    description = db.Column(db.Text)
    address = db.Column(db.String(100))  # ip and port，代表另一个docker_api_client


class HostMachineCPUInfo(TypedDict):
    physical_cores: int  # 物理核数
    logical_cores: int  # 逻辑线程数
    cpu_percentages: list[float]  # 每个CPU核心的占用率


class HostMachineMemoryInfo(TypedDict):
    total: int
    used: int


class HostMachineDiskInfo(TypedDict):

    device: str
    mountpoint: str
    total: int
    used: int
    free: int
    percent: float
    is_docker_dir_on_disk: bool


class HostMachineResourceInfoDict(TypedDict):
    online: bool
    cpu: HostMachineCPUInfo
    memory: HostMachineMemoryInfo
    disks: list[HostMachineDiskInfo]


DEFAULT_HOSTMACHINE_INFO_DATA: HostMachineResourceInfoDict = {
    "online": False,
    "cpu": {"physical_cores": 0, "logical_cores": 0, "cpu_percentages": []},
    "memory": {"total": 0, "used": 0},
    "disks": [],
}
